##
##  $Header: /pub/cvsroot/mydns/doc/Makefile.am,v 1.25 2002/07/15 00:09:45 bboy Exp $
##

MAN_PAGES		=	mydns.conf.5 mydns.8
EXTRA_DIST		=	$(MAN_PAGES:=.in) $(TEXI) README \
						support/texi2html texi2html.init \
						man pdf info html ps fdl.texi

TEXIVARS			=	variables.texi
SEDFILE 			=	../version.sed

TEXI				=	@PACKAGE_NAME@.texi
INFO				=	$(TEXI:texi=info)
HTML				=	$(TEXI:texi=html)
DEPS				=	$(TEXI) $(TEXIVARS)

## Creates a small .sed script to replace various variables
sedvars:
	if ! `test -f $(SEDFILE)`; then cd .. && make sedfile; fi

## Create a .texi file including the variables
variables.texi:
	@if `test -f $(TEXIVARS)`; then rm -f $(TEXIVARS); fi
	@echo "@set PKGDATE @PACKAGE_DATE@" >> $(TEXIVARS)
	@echo "@set PKGNAME @PACKAGE_NAME@" >> $(TEXIVARS)
	@echo "@set PKGVERSION @PACKAGE_VERSION@" >> $(TEXIVARS)
	@echo "@set PKGSTRING @PACKAGE_STRING@" >> $(TEXIVARS)
	@echo "@set PKGAUTHOR @PACKAGE_AUTHOR@" >> $(TEXIVARS)
	@echo "@set PKGBUGREPORT @PACKAGE_BUGREPORT@" >> $(TEXIVARS)
	@echo "@set PKGHOMEPAGE @PACKAGE_HOMEPAGE@" >> $(TEXIVARS)
	@echo "@set PKGCOPYRIGHT @PACKAGE_COPYRIGHT@" >> $(TEXIVARS)

vars: sedvars variables.texi

## Create documentation for the `info' program
info: $(DEPS)
	-@MAKEINFO@ -o info/$(INFO) $(TEXI) 2> /dev/null
	@if ! test -f info/$(INFO); then \
		echo; echo "*** GNU info documentation not created - you probably need makeinfo."; \
		echo "*** See http://www.fsf.org/software/texinfo/texinfo.html for details."; echo; \
	fi

## Create HTML files from the texinfo source
html-doc: $(DEPS)
	-@@PERL@ support/texi2html -init_file=texi2html.init $(TEXI) 2> /dev/null
	@if ! test -f html/$(HTML); then \
		echo; echo "*** HTML documentation not created - do you have perl?"; echo; \
	else \
		if test -f ../extras/graphics/mydns-logo.png; then \
			cp -f ../extras/graphics/mydns-logo.png html; \
		fi; \
	fi

## Create HTML files (for the home page) from the texinfo source
html-doc-web: $(DEPS)
	@PERL@ support/texi2html -init_file=@WEBROOT@/doc/texi2html.init $(TEXI)

## Create PDF output
pdf: $(DEPS)
	cp -f $(TEXI) tmp.texi
	pdftex --interaction=nonstopmode tmp.texi
	texindex tmp.??
	pdftex --interaction=nonstopmode tmp.texi
	texindex tmp.??
	pdftex --interaction=nonstopmode tmp.texi
	mv tmp.pdf pdf/mydns.pdf
	rm -f tmp.*

## Process <manpage>.in to create <manpage>
manpages: $(MAN_PAGES:=.in)
	for f in $(MAN_PAGES); do sed -f $(SEDFILE) $$f.in > man/$$f; done

mydns_letter.ps: $(DEPS)
	MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) --batch --clean $<
	$(DVIPS) -t letter mydns.dvi -o ps/$@

mydns_a4.ps: $(DEPS)
	MAKEINFO='$(MAKEINFO) -I $(srcdir)' $(TEXI2DVI) --batch --clean $<
	$(DVIPS) -t a4 mydns.dvi -o ps/$@

ps: mydns_letter.ps mydns_a4.ps

all: vars manpages info html-doc

clean:
	rm -f *~ core* $(TEXIVARS) info/$(INFO) html/*.html html/mydns-logo.png pdf/mydns.pdf
	for f in $(MAN_PAGES); do rm -f man/$$f; done
	rm -f mydns.dvi ps/mydns_letter.ps ps/mydns_a4.ps

man-install: manpages
	for f in $(MAN_PAGES); do \
	  $(INSTALL) -d $(DESTDIR)$(mandir)/man`echo $$f | sed -e 's/^.*\\.//'`; \
	  $(INSTALL_DATA) man/$$f $(DESTDIR)$(mandir)/man`echo $$f | sed -e 's/^.*\\.//'`/$$f; \
	done

info-install: info
	if test -f info/$(INFO); then \
		$(INSTALL) -d $(DESTDIR)$(infodir); \
		$(INSTALL_DATA) info/$(INFO) $(DESTDIR)$(infodir)/$(INFO); \
	fi

install: all man-install info-install

## Target the author uses to install docs on the homepage:
release: vars manpages html-doc-web pdf ps
	rm -f info/$(INFO)
	rm -f @WEBROOT@/doc/pdf/*.pdf && cp -a pdf/*.pdf @WEBROOT@/doc/pdf
	rm -f @WEBROOT@/doc/ps/*.ps && cp -a ps/*.ps @WEBROOT@/doc/ps
	rm -f @WEBROOT@/doc/man/*.[0-9] && cp -a man/*.[0-9] @WEBROOT@/doc/man

## vi:set ts=3:
